import java.util.Hashtable;
import java.util.StringTokenizer;
import java.util.Vector;

class P793 {

	private static Hashtable graph;
	private static long[] answer;
	private static int[] nr;
	private static int n;

	public static void main(String[] args) {
		int cases = Integer.parseInt(readLn());
		readLn();
		for (int k = 0; k < cases; k++) {
			process(Integer.parseInt(readLn()));
			if (k + 1 != cases) System.out.println();
		}
	}
	
	private static void process(int x) {
//		graph = new Hashtable();
//		for (long k = 1; k <= n; k++) {
//			N no = new N();
//			no.id = k;
//			graph.put(new Long(k), no);
//// System.out.println(graph);
//		}
//
		answer = new long[2];

		n = x;
		
		nr = new int[x+1];
		
		for (int i=0;i<x;i++) nr[i]=i;
		
		String line = readLn();
		while (line != null &&  !"".equals(line)) {
			subProcess(line);
			line = readLn();
		}
		System.out.println(answer[0] + "," + answer[1]);
	}

	private static void subProcess(String line) {
		StringTokenizer st = new StringTokenizer(line);
		char cmd = st.nextToken().charAt(0);
		int begin = Integer.parseInt(st.nextToken());
		int end = Integer.parseInt(st.nextToken());
		
		switch (cmd) {
			case 'c':
//				connect(begin, end);
				unionID(nr[begin-1],nr[end-1]);
				break;
			case 'q':
				if (question(begin,end)) {
					answer[0]++;
				} else {
					answer[1]++;
				}
//				query(begin, end);
				break;
		}
	}

	private static void query(long begin, long end) {

		
		N a = (N) graph.get(new Long(begin));
		N b = (N) graph.get(new Long(end));
		
		Vector toVisit = new Vector();
		
		int length = a.adj.size();
		for (int k = 0; k < length; k++) {
			toVisit.addElement(a.adj.elementAt(k));
		}
		
		while (!toVisit.isEmpty()) {
			N visited = (N) toVisit.elementAt(0);
			toVisit.removeElement(visited);
			visited.visited = true;
			
			if (visited.id == b.id) {
				answer[0]++;
				return;
			}
			
			int l = visited.adj.size();
			for (int k = 0; k < l; k++) {
				N toVisitNode = (N)visited.adj.elementAt(k);
				if (!toVisitNode.visited) {
					toVisit.addElement(toVisitNode);
				}
			}
			
		}
		
		answer[1]++;
		
		
	}

	private static void connect(long begin, long end) {
// System.out.println(graph);
//		
// System.out.println(begin);
// System.out.println(end);
		
		N a = (N) graph.get(new Long(begin));
		N b = (N) graph.get(new Long(end));
		
		a.adj.addElement(b);
		b.adj.addElement(a);
		
// System.out.println(graph);
	}

	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString()).trim();
	}

	
	
	
	static void unionID(int what, int newID) {
		for (int i = 0; i < n; i++) {
			if (nr[i] == what)
				nr[i] = newID;
		}
	}

	static boolean question(int n1, int n2) {
		if (nr[n1 - 1] == nr[n2 - 1])
			return true;
		else
			return false;
	}

	
	
	
	
	
	
	
}

class N {
	boolean visited = false;
	long id;
	Vector adj = new Vector();
	
	
	public String toString() {
		return "ID: " + id;
	}
}